package com.faithbj.common.dao.impl;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.faithbj.common.dao.DictionaryDao;
import com.faithbj.common.dao.impl.BaseDaoImpl;
import com.faithbj.common.model.Dictionary;

/**
 * @author jrn E-mail: rinanjin@gmail.com
 * @version 0.1 
 * 创建时间：2012-6-5 下午10:52:00
 * 类说明
 */
@Repository("dictionaryDao")
public class DictionaryDaoImpl extends BaseDaoImpl<Dictionary, String>
		implements DictionaryDao
{
	@Override
	public List<Dictionary> getLev1List()
	{
		Criteria criteria = getSession().createCriteria(Dictionary.class);
		criteria.setProjection(Projections.groupProperty("typeName"));
		@SuppressWarnings("unchecked")
		List<Dictionary> dictionaryList = criteria.list();
		return dictionaryList;
	}

	public List<Dictionary> getLev2List()
	{
		Criteria criteria = getSession().createCriteria(Dictionary.class);
		criteria.setProjection(Projections.groupProperty("name"));
		criteria.add(Restrictions.eq("hasChildren", true));
		@SuppressWarnings("unchecked")
		List<Dictionary> dictionaryList = criteria.list();
		return dictionaryList;
	}

	@Override
	public List<Dictionary> getListByTypeName(String typeName)
	{
		Criteria criteria = getSession().createCriteria(Dictionary.class);
		criteria.add(Restrictions.eq("typeName", typeName));
		@SuppressWarnings("unchecked")
		List<Dictionary> dictionaryList = criteria.list();
		return dictionaryList;
	}
}
